// mysql 函数
// 
export const sqlFragment = {
    user: `
        JSON_OBJECT(
            'id', user.id,
            'name', user.name,
            'avatar', IF(COUNT(avatar.id), 1, null)
        ) as user
    `,
    totalComments: `
        (
            SELECT 
                COUNT(comment.id) 
            FROM 
                comment 
            WHERE 
                comment.postId = post.id
        ) as totalComments
    `,
    totalLikes: `
        (
            SELECT
                COUNT(user_like_post.postId)
            FROM
                user_like_post
            WHERE
                user_like_post.postId = post.id
        ) as totalLikes
    `,
    totalTags: `
        (
            SELECT
                
        )
    `
    leftJoinUser: `
         LEFT JOIN user 
            ON user.id = post.userId
         LEFT JOIN avatar 
            ON user.id = avatar.userId
    `
}